package com.bdqn.zhao.controller;


import com.bdqn.zhao.pojo.IpPark;
import com.bdqn.zhao.service.IpParkService;
import com.bdqn.zhao.service.SysDistrictsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 园区表 前端控制器
 * </p>
 *
 * @author zhangsan
 * @since 2023-04-24
 */
@Controller
@RequestMapping("/ipPark")
public class IpParkController {

    @Autowired
    private IpParkService ipParkService;
    @Autowired
    private SysDistrictsService sysDistrictsService;



    // 全查 园区列表 楼宇列表使用
    @ResponseBody
    @GetMapping("/selectAlls")
    public String selectAlls(HttpSession session) {
        return ipParkService.selectAllipParks(session);
    }


    // 园区列表 --条件查询 --上下页分页
    @ResponseBody
    @GetMapping("/selectOne/{index}/{count}")
    public Map<String, Object> selectOne(@PathVariable int index,
                                         @PathVariable int count,
                                         @RequestParam(required = false) String parkName) {
        return ipParkService.selectOneipPark(index, count, parkName);
    }


    // 园区列表  --修改园区上下架状态
    @ResponseBody
    @PostMapping("/updateStatus/{id}/{status}")
    public Map<String, Object> updateStatus(@PathVariable int parkid,
                                            @PathVariable int status) {
        return ipParkService.updateStatus(parkid, status);
    }


    // 上传图片
    @PostMapping("/uploadProductImage")
    @ResponseBody
    public Map<String, Object> uploadProductImage(@RequestParam("alogoPicPath") MultipartFile alogoPicPath, int imageType, HttpSession session) {
        return ipParkService.uploadProductImage(alogoPicPath, imageType, session);
    }

    // 园区列表 -- 新增园区信息
    @ResponseBody
    @PostMapping("/ipParksave")
    public Boolean ipParksave(IpPark ipPark,
                              @RequestParam(required = false) @RequestBody List<String> ipParkSingleImageList,
                              @RequestParam(required = false) List<String> ipParkImageList,
                              @RequestBody Map hasaMap, HttpSession session) {
        return ipParkService.addIpPark(ipPark, ipParkSingleImageList, ipParkImageList, hasaMap, session);
    }


    // 园区列表 -- 根据省id查询出对应子级
    @GetMapping("/address/{id}")
    @ResponseBody
    public Object address(@PathVariable Integer id) {
        return sysDistrictsService.address(id);
    }


    // 园区列表 -- 修改园区信息页面
    @ResponseBody
    @PostMapping("/update/{pid}")
    public Map<String,Object> updates(@PathVariable int pid,
                         IpPark ipPark,
                         @RequestParam(required = false) List<String> ipParkSingleImageList,
                         @RequestParam(required = false) List<String> ipParkImageList,
                         @RequestBody Map hasaMap, HttpSession session) {
        return ipParkService.updates(pid, ipPark, ipParkSingleImageList, ipParkImageList, hasaMap, session);
    }


    // 跳转-------------------------------------------------------------------------------------------------------

    // 全查 园区列表 带分页
    @GetMapping("/selectAll")
    public String selectAll(HttpSession session) {
        ipParkService.selectAllipPark(session);
        return "/ipPark";
    }

    // 园区列表 -- 跳转新增园区信息 并查询出省份信息
    @ResponseBody
    @GetMapping("/addipPark")
    public String addipPark(HttpSession session) {
        return sysDistrictsService.selectDistricts(session);
    }

    // 园区列表 -- 跳转修改园区信息页面 并查询出园区信息
    @ResponseBody
    @GetMapping("/updateipPark/{pid}")
    public String updateipPark(@PathVariable int pid, HttpSession session) {
        // 跳转前将园区地址查询显示
        return sysDistrictsService.selectOne(ipParkService.updateipPark(pid, session), session);
    }


}

